<?php 
include('../Connections/KRAPPERCON.php');
//include('../Connections/Accesos.php');

$oper = $_POST['oper'];

if ($oper == 'byFact'){
$fact = $_POST['doc'];
$mon_md = 0;
$mon_ml = 0;

$sql = "call sp_getPagosbyFact('".$fact."');";
$res = $mysqli->query($sql);
doEcho($sql);

?>

<table width="100%" rules="all" class="tableIn" border="1" cellspacing="0" cellpadding="0">
<thead>
  <tr>
    <th>Doc.Pago</th>
    <th>Doc.Factura</th>
    <th>Usuario</th>
    <th>Referencia</th>
    <th>Agencia</th>
    <th>Fec.Documento</th>
    <th>Clase</th>
    <th>Moneda</th>
    <th>Ret.</th>
    <th>Det.</th>
    <th>MD</th>
    <th>ML</th>
    <th>&nbsp;</th>
  </tr>
  </thead>
  <tbody>
  <?php 
  if($res){
  	while($row = $res->fetch_assoc()){
	$mon_md = $mon_md + $row['montoMD'];
	$mon_ml = $mon_ml + $row['montoPen'];
  ?>
  <tr>
    <td><span onClick="vdp1(this)" class="lnk"><?php echo $row['idPago']; ?></span></td>
    <td><?php echo $row['documID']; ?></td>
    <td><?php echo $row['UserID']; ?></td>
    <td><?php echo $row['refPago']; ?></td>
    <td><?php echo $row['agePago']; ?></td>
    <td><?php echo $row['fecDoc']; ?></td>
    <td><?php echo $row['claPago']; ?></td>
    <td><?php echo $row['monPago']; ?></td>
    <td class="qt"><?php echo $row['montoRet']; ?></td>
    <td class="qt"><?php echo $row['montoDet']; ?></td>
    <td class="qt"><?php echo $row['montoMD']; ?></td>
    <td class="qt"><?php echo $row['montoPen']; ?></td>
    <td><?php echo ""; ?></td>
  </tr>
  <?php
  	} 
	$res->close();
	$mysqli->check_result();
  }
  ?>
  </tbody>
  <tfoot>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th class="qt">&nbsp;</th>
    <th class="qt">&nbsp;</th>
    <th class="qt"><?php echo myRound($mon_md); ?></th>
    <th class="qt"><?php echo myRound($mon_ml); ?></th>
    <th>&nbsp;</th>
  </tr>
  </tfoot>
</table>

<?php 
}
?>
<script type="text/javascript">
function vdp1(obj){
	var doc = obj.innerHTML;
	loadPage('Procesos/MantCompensaciones.php',{ oper : 'view', doc : doc });
}
</script>